#include "mybutton.h"
#include "ui_mybutton.h"
#include"qpainter.h"
#include <QMouseEvent>
#include "qdebug.h"
myButton::myButton(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::myButton)
{
    ui->setupUi(this);
}

myButton::~myButton()
{
    delete ui;
}
void myButton::paintEvent(QPaintEvent *event)
{
    //通过这种方式可以将图片平铺到窗口上
    //使用样式表可以很方便设置界面，而且非常高效，还能让界面和逻辑分离
    //不过在本例中由于是顶层窗口，所以直接设置样式表也不会显示。
    //所以样式表比较适合子窗口来使用。
//    qDebug()<<"paintEvent";
    QPainter painter(this);
    if(mouseFlag==0)
        painter.drawPixmap(rect(),QPixmap(":/images/group_view/group_show_btn1.png"),QRect());
    if(mouseFlag==1)
        painter.drawPixmap(rect(),QPixmap(":/images/group_view/group_show_btn2.png"),QRect());

}

void myButton::mouseReleaseEvent(QMouseEvent *event){
    mouseFlag=0;
    qDebug()<<"mouseReleaseEvent";
    update ();
}
void myButton::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
        {
            mouseFlag=1;
            qDebug()<<"LeftButton";
        }
    update ();

}
void myButton::mouseDoubleClickEvent(QMouseEvent *event)
{
    emit Clicked();
}

void myButton::enterEvent(QEvent *event)
{
    mouseFlag=1;
    update ();
}
void myButton::leaveEvent(QEvent *event)
{
    mouseFlag=0;
    update ();
}
void myButton::setHR(QString pr)
{
    if(iseleoff)
        ui->label_pr_v->setText("--");
    else
        ui->label_pr_v->setText(pr);
}
void myButton::setUserID(QString userID,QString userName)
{
    ui->label_userName->setText("iD:"+userID+"\t姓名:"+userName);
}
void myButton::setOx(QString ox)
{
    if(iseleoff)
        ui->label_ox_v->setText("--");
    else
        ui->label_ox_v->setText(ox);
}
void myButton::setPidian(QString pd)
{
    if(iseleoff)
         ui->label_pd_v->setText("--");
    else
        ui->label_pd_v->setText(pd);
}
void myButton::setMp(QString Mp)
{
    if(iseleoff)
        ui->label_mp_v->setText("--");
    else
       ui->label_mp_v->setText(Mp);

}
void myButton::setColor(int eleoff)
{
    iseleoff=eleoff;
    if(eleoff==1)
    {
        ui->label_mp->setStyleSheet("color:#FF0000;");
        ui->label_ox->setStyleSheet("color:#FF0000;");
        ui->label_pr->setStyleSheet("color:#FF0000;");
        ui->label_pd->setStyleSheet("color:#FF0000;");
    }else
    {
        ui->label_mp->setStyleSheet("color:#FFFFFF;");
        ui->label_ox->setStyleSheet("color:#FFFFFF;");
        ui->label_pr->setStyleSheet("color:#FFFFFF;");
        ui->label_pd->setStyleSheet("color:#FFFFFF;");
    }
}
